<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定的简化写法</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //声明类式组件
        class App extends React.Component {

                state = {
                    isNight: false
                };

                //为实例对象添加方法
                click = () => {
                    // console.log('----',this);
                    this.setState({
                        isNight: !this.state.isNight
                    })
                }

                //构造方法 this 指向实例对象
                // constructor(){
                //     super();
                //     this.click = () => {
                //         console.log(this);
                //     }
                // }

                //App 的实例对象, 调用 render 方法.
                render() {
                    let isNight = this.state.isNight;

                    return (
                        <div>
                        <h2>
                            至尊宝, 我是 {isNight ? "青霞仙子" : "紫霞仙子"}
                        </h2>
                        {/**
                            <button onClick={
                                () => {
                                    this.setState({
                                        isNight: !isNight
                                    })
                                }
                            }>点击切换白天与黑夜</button>
                        */}
                        <button onClick={this.click}>点击切换白天与黑夜</button>
                    </div>
                    );
                }
            }

            ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>